package leetcode_401_500;

public class LeeCode_459 {
    public static void main(String[] args) {
//        System.out.println(repeatedSubstringPattern("abab"));
        System.out.println(repeatedSubstringPattern("aabaabaab"));
    }
    private static boolean repeatedSubstringPattern(String s) {
        int n = s.length();
        for (int i = 0; i < n / 2; i++) {
            String son = s.substring(0, i + 1);
            int index = 0, j = i + 1;
            boolean flag = true;
            while (j < n){
                if (s.charAt(j) != son.charAt(index)){
                    flag = false;
                    break;
                }
                index++;
                if (index == son.length()){
                    index = 0;
                }
                j++;
            }
            if (flag && index == 0){
                return true;
            }
        }
        return false;
    }
}
